package com.github.blanexie.nexusj.support

import cn.hutool.cache.file.LFUFileCache
import cn.hutool.core.util.CharsetUtil
import cn.hutool.crypto.SecureUtil
import cn.hutool.crypto.digest.MD5
import java.io.InputStream


val tempDir = System.getProperty("java.io.tmpdir")
val UTF8 = CharsetUtil.CHARSET_UTF_8
val nexusKey = "5zBaK2nxY5LFda3F95O2cIpuXe"
val AES = SecureUtil.aes(nexusKey.toByteArray(UTF8))


//参数1：容量，能容纳的byte数
//参数2：最大文件大小，byte数，决定能缓存至少多少文件，大于这个值不被缓存直接读取
//参数3：超时。毫秒
val fileCache = LFUFileCache(1024 * 1024 * 10, 1024 * 100, 60 * 60_000)




fun getContentType(name: String): String {
    if (name.endsWith(".jpg", ignoreCase = false)
        || name.endsWith(".jpeg", ignoreCase = false)
    ) {
        return "image/jpeg";
    }
    if (name.endsWith(".png", ignoreCase = false)) {
        return "image/png";
    }
    if (name.endsWith(".gif", ignoreCase = false)) {
        return "image/gif";
    }

    return "application/octet-stream"

}


data class UploadFile(
    val name: String,
    val orginalName: String,
    val suffix: String,
    val inputStream: InputStream
)